import 'package:flutter/material.dart';

/// author：william on 2021/4/9 13:42
/// email：362661044@qq.com
///
/// 高级筛选行的容器
class AdvancedFilterItemContainer extends StatelessWidget {
  final Widget child;
  final String title;
  final Widget suffixChild;
  final double rowHeight;
  final bool isRequired;

  AdvancedFilterItemContainer({Key key, this.suffixChild, @required this.child, @required this.title, this.rowHeight = 40, this.isRequired = false}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return IntrinsicHeight(
      child: Row(
        children: [
          _buildText(context),
          SizedBox(width: 12),
          Flexible(fit: FlexFit.tight, child: this.child ?? SizedBox()),
          Visibility(
            visible: this.suffixChild != null,
            child: Container(
              margin: EdgeInsets.only(left: 8),
              child: this.suffixChild,
            ),
          )
        ],
      ),
    );
  }

  /// 创建标题
  Widget _buildText(BuildContext context) {
    return Container(
      width: 64,
      child: Align(
        alignment: Alignment.topLeft,
        child: Container(
          alignment: Alignment.centerLeft,
          height: rowHeight,
          child: RichText(
            text: TextSpan(children: [
              TextSpan(text: this.title, style: Theme.of(context).textTheme.bodyText2),
              WidgetSpan(child: Text('* ', style: TextStyle(color: isRequired == true ? Colors.red : Colors.transparent))),
            ]),
          ),
        ),
      ),
    );
  }
}
